package lc.q150_200;

public class Q162 {

    public static void main(String[] args) {
        Q162 q162 = new Q162();
        System.out.println(q162.findPeakElement(new int[]{Integer.MIN_VALUE}));
    }

    public int findPeakElement(int[] nums) {
        return findPeakElement(nums, 0, nums.length);
    }

    private boolean compareLeft(int[] nums, int index) {
        if (index == 0) {
            return true;
        }
        return nums[index - 1] < nums[index];
    }

    private boolean compareRight(int[] nums, int index) {
        if (index == nums.length - 1) {
            return true;
        }
        return nums[index + 1] < nums[index];
    }

    private int findPeakElement(int[] nums, int start, int end) {
        int mid = (start + end) / 2;
        if (compareLeft(nums, mid)) {
            if (compareRight(nums, mid)) {
                return mid;
            } else {
                return findPeakElement(nums, mid + 1, end);
            }
        } else {
            return findPeakElement(nums, start, mid - 1);
        }
    }
}
